package com.chebaohui.iqs.service.impl.deal.taiping.ev;
import com.alibaba.fastjson.JSONObject;
import com.chebaohui.iqs.config.CompanyValue;
import com.chebaohui.iqs.service.impl.deal.taiping.DirectTp;
import com.chebaohui.iqs.service.impl.deal.taiping.PublicNew;
import com.chebaohui.iqs.service.impl.deal.taiping.RequestHead;
import com.chebaohui.iqs.service.impl.deal.taiping.ResTaiPing;
import com.chebaohui.iqs.service.impl.deal.util.StringUtil;

/**
 * E03-获取订单号
 * 
 * @author xielonghai
 * @version 2016-07-06
 */
public class E03Request {

	/**
	 * 该接口初步设计根据用户输入的车牌号、身份证号、行驶城市编码等信息，获取订单号 **** String solutionCode, String
	 * groupNo, String salesmanCode,
	 * 
	 * @param session
	 *            会话ID--初始为空,后续调用为上次request返回
	 * @param cityCode
	 *            行驶城市代码(N)-国际城市编码,网销平台业务必传
	 * @param solutionCode
	 *            子协议代码(N)-非网销平台业务，且无申报过团队号，需要传值
	 * @param groupNo
	 *            团队号(N)-根据需求受理评估表，若是申报了团队号，则需要传送，其他销售信息无需传送
	 * @param salesmanCode
	 *            业务员代码(N)
	 * @param licenseNo
	 *            车牌号(Y)-若是新车，传送“暂未上牌”
	 * @param identifyNumber
	 *            车主身份证号码(Y)
	 * @return
	 */
	public static ResTaiPing requestE03(String session, String cityCode, String licenseNo, String identifyNumber) {
		// 接口描述
		String value = CompanyValue.TAIPING + ":辅助接口-根据车牌号:" + licenseNo + ",及身份证号:" + identifyNumber + ",获取订单号";

		String[] key = { "order" };
		return DirectTp.request(value, PublicNew.REQUEST_URL + "/orderNo",
				getRequest(session, licenseNo, identifyNumber, cityCode), key);
	}

	/**
	 * 获取--E03-车辆是否可以直接报价------请求参数
	 * 
	 * @param licenseNo
	 *            车牌号
	 * @return
	 */
	private static String getRequest(String session, String licenseNo, String identifyNumber, String cityCode) {
		JSONObject head = RequestHead.getHead(session);
		String request = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
		request = request + "\n" + "<request>";
		request = request + "\n" + "<head>";

		request = request + "\n\t" + "<msgId>" + head.getString("msgId") + "</msgId>";
		request = request + "\n\t" + "<timeStamp>" + head.getString("timeStamp") + "</timeStamp>";
		request = request + "\n\t" + "<session>" + head.getString("session") + "</session>";
		request = request + "\n\t" + "<userCode>" + head.getString("userCode") + "</userCode>";

		request = request + "\n" + "</head>";
		request = request + "\n" + "<body>";

		request = request + "\n\t" + "<vehicle>";
		request = request + "\n\t\t" + "<licenseNo>" + licenseNo + "</licenseNo>";
		request = request + "\n\t" + "</vehicle>";

		request = request + "\n\t" + "<sales>";
		if (!StringUtil.isNulls(cityCode)) {// 城市代码
			request = request + "\n\t\t" + "<cityCode>" + cityCode + "</cityCode>";
		}
		request = request + "\n\t\t" + "<groupNo>" + PublicNew.groupNo + "</groupNo>";// 团队号
		request = request + "\n\t" + "</sales>";

		request = request + "\n\t" + "<carOwner>";
		request = request + "\n\t\t" + "<identifyNumber>" + identifyNumber + "</identifyNumber>";
		request = request + "\n\t" + "</carOwner>";

		request = request + "\n" + "</body>";
		request = request + "\n" + "</request>";
		return request;
	}
}
